home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 June: Reference Library / Dev.CD Jun 95 / Dev.CD Jun 95.toast / What's New? / New System Software Extensions / QuickDraw 3D ß / Programming / SampleCode / CommonSample / fileStuff.c next >
Encoding:
Text File  |  1995-03-30  |  2.2 KB  |  112 lines  |  [TEXT/MPCC]

  1. // hack to dump the mf data
  2. #include "QD3D.h"
  3. #include "QD3DGroup.h"
  4. #include "QD3DIO.h"
  5. #include "QD3DStorage.h"
  6. #include "QD3DView.h"
  7. #include <StandardFile.h>
  8.  
  9. #include "FileStuff.h"
  10.  
  11.  
  12. void WriteGroupToFile( TQ3FileObject file, TQ3GroupObject theData, TQ3ViewObject theView)
  13. {
  14.     TQ3GroupPosition    gPos;
  15.     TQ3Object            object;
  16.     TQ3SharedObject        viewHints;
  17.     TQ3ViewStatus        fileStatus;
  18.     
  19.     if (Q3File_OpenWrite(file, kQ3FileModeNormal | kQ3FileModeText) == kQ3Success )
  20.     {
  21.     
  22.         Q3View_StartWriting(theView, file);
  23.  
  24.         if (theView == NULL)
  25.             viewHints = NULL;
  26.         else
  27.             viewHints = Q3ViewHints_New(theView);
  28.             
  29.         if (viewHints != NULL)
  30.         {
  31.             if (Q3Object_Submit(viewHints, theView) == kQ3Failure)
  32.             {
  33.                 Q3File_Cancel(file);
  34.                 return;
  35.             }
  36.         }
  37.             
  38.         do {
  39.             if (theData != NULL)
  40.             {
  41.                 TQ3Status status;
  42.                 
  43.                 status = Q3Group_GetFirstPosition(theData, &gPos);
  44.                 
  45.                 while (gPos != NULL && status == kQ3Success)
  46.                 {
  47.                     
  48.                     Q3Group_GetPositionObject(theData, gPos, &object);
  49.                     status = Q3Object_Submit(object, theView);
  50.                     Q3Object_Dispose(object);
  51.                     
  52.                     if (status != kQ3Failure)
  53.                     {
  54.                         Q3Group_GetNextPosition(theData, &gPos);
  55.                     }
  56.                 }
  57.             }
  58.     
  59.         } while ((fileStatus = Q3View_EndWriting(theView)) == kQ3ViewStatusRetraverse);
  60.             
  61.         if( Q3File_Close(file) == kQ3Failure ) {
  62.             return;
  63.         }
  64.     }
  65.     return ;
  66. }
  67.  
  68. Boolean WriteFile(TQ3GroupObject theData, TQ3ViewObject theView )
  69. {
  70.     Str255                thePrompt = "\pGimmie a file:", theName = "\pMetafile.3mf";
  71.     StandardFileReply    theReply;
  72.     OSErr                theResult;
  73.     long                length;
  74.     char                *bufPtr;
  75.     short                myRefNum ;
  76.     
  77.  
  78.     StandardPutFile( (ConstStr255Param) &thePrompt, (ConstStr255Param) &theName, &theReply);
  79.  
  80.     if (theReply.sfGood) {
  81.         if (!theReply.sfReplacing) {
  82.             if ((theResult = FSpCreate(&theReply.sfFile, '????', 'TEXT', theReply.sfScript)) != noErr) {
  83.                 SysBeep(1);
  84.                 return(false);
  85.             }
  86.         }
  87.     }
  88.     
  89.     if( theData ) {
  90.         TQ3StorageObject    storage;
  91.         TQ3FileObject        fd;
  92.         
  93.         storage = Q3FSSpecStorage_New( &theReply.sfFile );        
  94.         if (storage == NULL)
  95.             goto bail;
  96.         
  97.         fd = Q3File_New();
  98.         if (fd == nil)
  99.             goto bail;
  100.  
  101.         Q3File_SetStorage(fd, storage);
  102.         Q3Object_Dispose(storage);
  103.         
  104.         WriteGroupToFile( fd, theData, theView ) ;
  105.  
  106.         Q3Object_Dispose(fd);
  107.     }
  108.     return(noErr);
  109. bail:
  110.     return(fnOpnErr);
  111. }
  112.